package com.ssl.basics.thread.lock;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 描述：
 *
 * @author shi_senlin
 * @create 2021/07/06 22:34
 */
@Slf4j(topic = "com.ssl.lock")
public class Ticket {
    private int count = 30;

    private Lock lock = new ReentrantLock();

    public void sale() {
        try {
            lock.lock();
            if (count > 0) {
                log.info("卖之前 {} 张， 剩余 {} 张", count--, count);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
    }
}
